﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace lchealthy
{
    public partial class frmCustorInventer : Form
    {
        public frmCustorInventer()
        {
            InitializeComponent();
        }
        int cnum = -1;
        public frmCustorInventer(int i)
        {
            cnum = i;
            InitializeComponent();
        }
        private void btnEdite_Click(object sender, EventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //string sql = "";
            //DataSet ds = DbHelperOleDb.ExecuteSql(sql);
        }

        private void frmCustorInventer_Load(object sender, EventArgs e)
        {
            if (cnum != -1)
            {
                string sql = "";
               int k = DbHelperOleDb.ExecuteSql(sql);
               if (k >= 1)
               {
                   MessageBox.Show("已经把物品寄存成功！");
               }
               else
               {
                   MessageBox.Show("物品寄存失败！");
               }
                //把购买的寄存的产品存入数据库
            }
            else
            {
                bind();
            }

        }

        private void bind()
        {
            string sql = "SELECT customer.cid, customer.cname, customer.cphone, depositinfo.dpnum, ProductInfo.PID, ProductInfo.PName FROM (customer INNER JOIN depositinfo ON customer.cid = depositinfo.CID) INNER JOIN ProductInfo ON depositinfo.PID = ProductInfo.PID";
            DataSet ds = DbHelperOleDb.Query(sql);
            cmbCname.DataSource = ds.Tables[0];
            cmbCname.DisplayMember = "cname";
            cmbCname.ValueMember = "CID";
            //int i = (int)cmbCname.SelectedValue;
            //MessageBox.Show(i.ToString());
            //txtTel.Text = ds.Tables[0].Rows[i - 1]["cphone"].ToString();
            cmbPname.DataSource = ds.Tables[0];
            cmbPname.DisplayMember = "Pname";
            cmbPname.ValueMember = "PID";
            int j = (int)cmbPname.SelectedValue;
            //MessageBox.Show(j.ToString());
            txtNum.Text = ds.Tables[0].Rows[j - 1]["dpnum"].ToString();
        }

        private void cmbCname_SelectedValueChanged(object sender, EventArgs e)
        {
            //bind();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bind();
        }

        

       
    }
}
